﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using HPIT.RentHouse.Admin.Models;
using HPIT.RentHouse.Common;
using HPIT.RentHouse.Service;
using HPIT.RentHouse.WebAPI.Models;

namespace HPIT.RentHouse.WebAPI.Controllers
{
    public class RolesController : ApiController
    {
        /// <summary>
        /// 获取角色列表信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public AjaxResult GetList()
        { 
            RolesService roleService = new RolesService();
            var list = roleService.GetList();
            return new AjaxResult(ResultState.Success,"测试成功！",list);
        }
        //把参数封装成模型对象(类)
        //传参必须全部传，一个都不能少
        public AjaxResult GetPageList(int start,int length,string name)
        { 
            RolesService rolesService = new RolesService();
            int count = 0;
            var list = rolesService.GetList(start, length, name, ref count);
            PageModel pageModel = new PageModel();  
            pageModel.data = list;
            pageModel.recordsTotal = count; 
            pageModel.recordsFiltered = count;
            return new AjaxResult(ResultState.Success, "", pageModel);
        }
        //传参可以不传string类型的参数
        public AjaxResult GetPageList1([FromUri] RolesPageModel model)
        {
            RolesService rolesService = new RolesService();
            int count = 0;
            var list = rolesService.GetList(model.start,model.length,model.name,ref count);
            PageModel pageModel = new PageModel();
            pageModel.data = list;
            pageModel.recordsTotal = count;
            pageModel.recordsFiltered = count;
            return new AjaxResult(ResultState.Success, "", pageModel);
        }
        [HttpPost]
        public AjaxResult Delete(long id)
        { 
           RolesService roleService = new RolesService();   
           var list=roleService.Delete(id);
           return new AjaxResult(ResultState.Success, "删除角色成功", list);
        }
    }
}
